/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/routeLineService.ts" />
/// <reference path="../src/tms.ts" />

describe("routeLineService", () => {
    var injector: ng.auto.IInjectorService;
    var service: IRouteLineService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IRouteLineService>('routeLineService');
    });

    //常规无条件获取
    it('get routeLine list normal', (done) => {
        service.getList(null, null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("||0|10");
            done();
        }, (err) => {
            done.fail(err);
        });
    });

    //获取车辆编号包含 1 的线路列表
    it('get routeLine list by carid \'1 \' ', (done) => {
        service.getList('1', null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("1||0|10");
            done();
        }, (err) => {
            done.fail(err);
        });
    });

    //获取承运商编号包含 2 的线路列表
    it('get routeLine list by carrierid \'2 \' ', (done) => {
        service.getList(null, '2', 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|2|0|10");
            done();
        }, (err) => {
            done.fail(err);
        });
    });

    //获取车辆编号包含 1 和 承运商编号包含 2 的线路列表
    it('get routeLine list by carid \'1 \' and carrierid \'2 \' ', (done) => {
        service.getList('1', '2', 0, 10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("1|2|0|10");
            done();
        }, (err) => {
            done.fail(err);
        });
    });

    //添加线路
    it('add routeLine ', (done) => {
        service.add('江苏', '镇江', '江苏', '南京', '2', '2').then((res) => {
            expect(res.data.extData).toBe("江苏|镇江|江苏|南京|2|2");
            done();
        }, (err) => {
            done.fail(err);
        });
    });

    //删除线路
    it('delete routeLine', (done) => {
        service.delete('2', '1', '3').then((res) => {
            expect(res.data.extData).toBe("2|1|3");
            done();
        }, (err) => {
            done.fail(err);
        });
    });
});